/*
 * Copyright (c) 2009
 *   TrojansLab.  All rights reserved.
 *   Contributors:  Shahram Ghandeharizadeh, Jason Yap, Showvick Kalra, Jorge Gonzalez, Igor Shvager.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1.  Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Redistributions in any form must be accompanied by information on
 *    how to obtain complete source code for the TCache software and any accompanying
 *    software that uses the TCache software.  The source code must either be
 *    included in the distribution or be available for no more than the cost
 *    of distribution plust a nominal fee, and must be freely redistributable
 *    under reasonable conditions.  For an executable file, complete source
 *    means the source code for all modules it contains.  It does not include
 *    source code for all modules it contains.  It does not include source
 *    code for modules or files that typically accompany the major components
 *    of the operating system on which the executable file runs.
 *
 * This software is provided by TrojansLab LLC and contributors AS IS and any express or
 * implied warranties, including, but not limited to, the implied warranties
 * of merchantability, fitness for a particular purpose, or non-infringement,
 * are disclaimed.  In no even shall TrojansLab LLC and contributors be liable for
 * any direct, indirect, incidental, speical, exemplary, or consequential damages
 * (including, but not limited to, procurement of substitute goods or services;
 * loss of use, data, or profits; or business interuption) however caused and or any
 * theory of liability, whether in contract, strict liability, or tort (including
 * negligence or otherwise) arising in any way out of the use of this software,
 * even if advised of the possibility of such damage.
 */

#include "stdafx.h"
#include "TCQValue.h"


TCQValue::TCQValue()
:	m_intPart( 0 ),
	m_fractionalPart( 0.0 )
{
}


TCQValue::TCQValue(const TCQValue &val)
:	m_intPart( val.m_intPart ),
	m_fractionalPart( val.m_fractionalPart )
{
}

TCQValue::TCQValue(const int& int_part, const double& fractional_part)
:	m_intPart( int_part ),
	m_fractionalPart( fractional_part )
{
}

TCQValue::TCQValue( const double& fractional_part )
:	m_intPart( 0 ),
	m_fractionalPart( fractional_part )
{
}

const TCQValue TCQValue::operator +(const TCQValue &val) const
{
	TCQValue result(*this);
	result.m_intPart += val.m_intPart;
	result.m_fractionalPart += val.m_fractionalPart;
	return result;
}

const TCQValue TCQValue::operator +(const int &val) const
{
	TCQValue result(*this);
	result.m_intPart += val;
	return result;
}

const TCQValue TCQValue::operator -(const TCQValue &val) const
{
	TCQValue result(*this);
	result.m_intPart -= val.m_intPart;
	result.m_fractionalPart -= val.m_fractionalPart;
	return result;
}

const TCQValue TCQValue::operator -(const int &val) const
{
	TCQValue result(*this);
	result.m_intPart -= val;
	return result;
}

TCQValue & TCQValue::operator =(const TCQValue &val)
{
	m_intPart = val.m_intPart;
	m_fractionalPart = val.m_fractionalPart;
	return *this;
}

TCQValue & TCQValue::operator += ( const int& val )
{
	m_intPart += val;
	return *this;
}


bool TCQValue::operator ==(const TCQValue &val) const
{
	if( m_intPart == val.m_intPart && m_fractionalPart == val.m_fractionalPart )
		return true;

	return false;
}

bool TCQValue::operator !=(const TCQValue &val) const
{
	if( m_intPart != val.m_intPart || m_fractionalPart != val.m_fractionalPart )
		return true;

	return false;
}

bool TCQValue::operator >=(const TCQValue &val) const
{
	if( m_intPart >= val.m_intPart && m_fractionalPart >= val.m_fractionalPart )
		return true;

	return false;
}

bool TCQValue::operator <=(const TCQValue &val) const
{
	if( m_intPart <= val.m_intPart && m_fractionalPart <= val.m_fractionalPart )
		return true;

	return false;
}

bool TCQValue::operator >(const TCQValue &val) const
{
	if( m_intPart > val.m_intPart )
		return true;

	if( m_intPart == val.m_intPart && m_fractionalPart > val.m_fractionalPart )
		return true;

	return false;
}

bool TCQValue::operator <(const TCQValue &val) const
{
	if( m_intPart < val.m_intPart )
		return true;

	if( m_intPart == val.m_intPart && m_fractionalPart < val.m_fractionalPart )
		return true;

	return false;
}

std::ostream & operator <<(std::ostream& output, const TCQValue& val)
{
	output<< val.m_intPart << "_" << val.m_fractionalPart;
	return output;
}